#!/usr/bin/env python
# --*-- coding:utf-8 --*--
# author:g-y-b time:2020/6/9

import cv2
import numpy as np
import matplotlib.pyplot as plt
train = cv2.imread('./SIFTimg/5.jpg', 0)
query = cv2.imread('./SIFTimg/7.jpg', 0)
# 暴力匹配
orb = cv2.ORB_create()
kp1, des1 = orb.detectAndCompute(train, None)
kp2, des2 = orb.detectAndCompute(query, None)
# 针对ORB算法 NORM_HAMMING 计算特征距离 True判断交叉验证
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
# 特征描述子匹配
print(type(des1))
print(des1.shape)
matches = bf.match(des1, des2)


matches = sorted(matches, key=lambda x: x.distance)
# print(len(matches))
img3 = cv2.drawMatches(train, kp1, query, kp2, matches[:20],None,flags=2)
plt.imshow(img3), plt.show()